<?php
echo "order";
echo "<br>";
// $loginName = $_REQUEST["loginName"];
$loginName=$_SESSION["name"];
echo $loginName;
echo "<br>";

require_once("DButil.php");
$conn = getConn();

//获取登录的u_id
$sql="select u_id from t_user where u_login_name={$loginName}";
$result = mysqli_query($conn, $sql);
$uId=mysqli_fetch_assoc($result);
echo($uId["u_id"]);
echo "<br>";


//订单编号
$time=time();
$timeG=getdate($time);
$oNo=$timeG["year"].$timeG["mon"].$timeG["mday"].$timeG["hours"].$timeG["minutes"].$timeG["seconds"];
echo($oNo) ;
echo "<br>";

//数量（其实都为1）
if($oNum){
    $oNum++;
}else{
    $oNum=1;
}

echo($oNum) ;
echo "<br>";

$pName=$_SESSION["p_name3"];
$pPrice=$_SESSION["p_price3"];

//单价
$oTotal=$oNum*$pPrice;
echo($oTotal) ;

//待修改，如果没有数据是插入，有数据是修改
$sql1="insert into t_order (o_no,o_num,o_total,u_id)"
    ." values ('{$oNo}','{$oNum}','{$oTotal}','{$uId["u_id"]}')";

// echo $sql1;
$result1 = mysqli_query($conn, $sql1);
// var_dump($result1);
if($result1){
    echo "添加成功";
    header("location:http://localhost/20201229/php/yd/goods.php?loginName={$loginName}");
}
mysqli_close($conn);
?>